/*****************************************************************************
*    Copyright (C) 2008 ALi Corp. All Rights Reserved.
*    
*    Company confidential and Properietary information.       
*    This information may not be disclosed to unauthorized  
*    individual.    
*    File: win_net_local_seting.c
*   
*    Description: 
*    
*    History: 
*    Date           Athor        Version        Reason
*    ========       ========     ========       ========
*    2008/12/5      Roman		 1.0.0			Create         
*        
*****************************************************************************/
#include <sys_config.h>

#ifdef NETWORK_SUPPORT
#include <types.h>
#include <basic_types.h>
#include <mediatypes.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>
#include <osal/osal.h>
#ifndef NEW_DEMO_FRAME
#include <api/libpub29/lib_pub27.h>
#include <api/libpub29/lib_as.h>
#endif
#include <api/libosd/osd_lib.h>

#include "osdobjs_def.h"
#include "string.id"
#include "images.id"
#include "osd_config.h"

#include "menus_root.h"
#include "win_com.h"
#include "win_com_popup.h"
#include "win_com_list.h"
#include "win_signalstatus.h"
#include "win_com_menu_define.h"

#include <hld/net/net.h>
#include <api/libtcpip/lwip/inet.h>
#include <api/libtcpip/lwip/sockets.h>
#include <api/libtcpip/lwip/netdb.h>
#include <api/libtcpip/lwip/err.h>
#include <api/libtcpip/lwip/netif.h>
#include <api/libnet/libnet.h>

/*******************************************************************************
*   Objects definition
*******************************************************************************/
extern CONTAINER g_win_localsetting;

extern CONTAINER localset_item_con1;
extern CONTAINER localset_item_con2;
extern CONTAINER localset_item_con3;
extern CONTAINER localset_item_con4;
extern CONTAINER localset_item_con5;
extern CONTAINER localset_item_con6;
extern CONTAINER localset_item_con7;

extern TEXT_FIELD localset_item_txtname1;
extern TEXT_FIELD localset_item_txtname2;
extern TEXT_FIELD localset_item_txtname3;
extern TEXT_FIELD localset_item_txtname4;
extern TEXT_FIELD localset_item_txtname5;
extern TEXT_FIELD localset_item_txtname6;
extern TEXT_FIELD localset_item_txtname7;

extern MULTISEL localset_item_dhcp;
extern EDIT_FIELD localset_item_ip_addr;
extern EDIT_FIELD localset_item_subnet_mask;
extern EDIT_FIELD localset_item_gateway;
extern EDIT_FIELD localset_item_dns1;
extern EDIT_FIELD localset_item_dns2;

extern TEXT_FIELD localset_item_line1;
extern TEXT_FIELD localset_item_line2;
extern TEXT_FIELD localset_item_line3;
extern TEXT_FIELD localset_item_line4;
extern TEXT_FIELD localset_item_line5;
extern TEXT_FIELD localset_item_line6;
extern TEXT_FIELD localset_item_line7;

static VACTION localset_item_sel_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT localset_item_sel_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static VACTION  localset_item_edf_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT  localset_item_edf_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static VACTION localset_item_con_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT localset_item_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static VACTION localset_con_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT localset_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static UINT16 win_com_onoff_ids[];

#define WIN_SH_IDX    WSTL_WIN_BODYRIGHT_01_HD

#define CON_SH_IDX   WSTL_BUTTON_01_HD
#define CON_HL_IDX   WSTL_BUTTON_05_HD
#define CON_SL_IDX   WSTL_BUTTON_01_HD
#define CON_GRY_IDX  WSTL_BUTTON_07_HD

#define TXT_SH_IDX   WSTL_BUTTON_01_FG_HD
#define TXT_HL_IDX   WSTL_BUTTON_02_FG_HD
#define TXT_SL_IDX   WSTL_BUTTON_01_FG_HD
#define TXT_GRY_IDX  WSTL_BUTTON_07_HD

#define SEL_SH_IDX   WSTL_BUTTON_01_FG_HD
#define SEL_HL_IDX   WSTL_BUTTON_04_HD
#define SEL_SL_IDX   WSTL_BUTTON_01_FG_HD
#define SEL_GRY_IDX  WSTL_BUTTON_07_HD

#define EDF_SH_IDX   WSTL_BUTTON_01_FG_HD
#define EDF_HL_IDX   WSTL_BUTTON_04_HD
#define EDF_SL_IDX   WSTL_BUTTON_01_FG_HD
#define EDF_GRY_IDX  WSTL_BUTTON_07_HD

#define TXT_L_OF  	TXTN_L_OF
#define TXT_W  		TXTN_W
#define TXT_H		TXTN_H
#define TXT_T_OF	TXTN_T_OF

#define SEL_L_OF 	TXTS_L_OF
#define SEL_W  		TXTS_W
#define SEL_H		TXTS_H
#define SEL_T_OF	TXTS_T_OF

enum
{
    IDC_LOCALSET_DHCP = 1,
    IDC_LOCALSET_IP_ADDR,
    IDC_LOCALSET_SUBNET_MASK,
    IDC_LOCALSET_GATEWAY,
    IDC_LOCALSET_DNS1,    
    IDC_LOCALSET_DNS2,
    IDC_LOCALSET_APPLY,
};

#define LDEF_CON(root, varCon,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,conobj,focusID)     \
    DEF_CONTAINER(varCon,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, CON_SH_IDX,CON_HL_IDX,CON_SL_IDX,CON_GRY_IDX,   \
    localset_item_con_keymap,localset_item_con_callback,  \
    conobj, focusID,1)

#define LDEF_TXT(root,varTxt,nxtObj,l,t,w,h,resID)      \
    DEF_TEXTFIELD(varTxt,root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, TXT_SH_IDX,TXT_HL_IDX,TXT_SL_IDX,TXT_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_LEFT | C_ALIGN_VCENTER, 0,0,resID,NULL)

#define LDEF_EDIT(root, varNum, nxtObj, ID, l, t, w, h,style,cursormode,pat,pre,sub,str)	\
    DEF_EDITFIELD(varNum,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,ID,ID,ID,ID, l,t,w,h, EDF_SH_IDX,EDF_HL_IDX,EDF_SL_IDX,EDF_GRY_IDX,   \
    localset_item_edf_keymap,localset_item_edf_callback,  \
    C_ALIGN_CENTER | C_ALIGN_VCENTER, 20,0,style,pat,10,cursormode,pre,sub,str)

#define LDEF_MSEL(root, varNum, nxtObj, ID, l, t, w, h,style,cur,cnt,ptabl) \
    DEF_MULTISEL(varNum,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,ID,ID,ID,ID, l,t,w,h, SEL_SH_IDX,SEL_HL_IDX,SEL_SL_IDX,SEL_GRY_IDX,   \
    localset_item_sel_keymap,localset_item_sel_callback,  \
    C_ALIGN_CENTER | C_ALIGN_VCENTER, 20,0,style,ptabl,cur,cnt)

#define LDEF_EDIT_MENU_ITEM(root,varCon,nxtObj,varTxt,varNum,varLine,ID,IDu,IDd,l,t,w,h,\
                        resID,style,cursormode,pat,pre,sub,str) \
    LDEF_CON(&root,varCon,nxtObj,ID,ID,ID,IDu,IDd,l,t,w,h,&varTxt,ID)   \
    LDEF_TXT(&varCon,varTxt,&varNum,l + TXT_L_OF,t + TXT_T_OF,TXT_W,TXT_H,resID)    \
    LDEF_EDIT(&varCon,varNum,NULL/*&varLine*/ ,ID,l + SEL_L_OF ,t + SEL_T_OF,SEL_W,SEL_H,style,cursormode,pat,pre,sub,str)\
    LDEF_LINE(&varCon,varLine,NULL,1,1,1,1,1,l + LINE_L_OF, t + LINE_T_OF,LINE_W,LINE_H,0,0)

#define LDEF_SEL_MENU_ITEM(root,varCon,nxtObj,varTxt,varNum,varLine,ID,IDu,IDd,l,t,w,h,\
                        resID,style,cur,cnt,ptbl) \
    LDEF_CON(&root,varCon,nxtObj,ID,ID,ID,IDu,IDd,l,t,w,h,&varTxt,ID)   \
    LDEF_TXT(&varCon,varTxt,&varNum,l + TXT_L_OF,t + TXT_T_OF,TXT_W,TXT_H,resID)    \
    LDEF_MSEL(&varCon,varNum,NULL/*&varLine*/,ID, l + SEL_L_OF ,t + SEL_T_OF,SEL_W,SEL_H,style,cur,cnt,ptbl)\
    LDEF_LINE(&varCon,varLine,NULL,1,1,1,1,1,l + LINE_L_OF, t + LINE_T_OF,LINE_W,LINE_H,0,0)

#define LDEF_TXT_MENU_ITEM(root,varCon,nxtObj,varTxt,varLine,ID,IDu,IDd,l,t,w,h,resID) \
    LDEF_CON(&root,varCon,nxtObj,ID,ID,ID,IDu,IDd,l,t,w,h,&varTxt,ID)   \
    LDEF_TXT(&varCon,varTxt,NULL/*&varLine*/,l + TXT_L_OF,t + TXT_T_OF,TXT_W,TXT_H,resID)\
    LDEF_LINE(&varCon,varLine,NULL,1,1,1,1,1,l + LINE_L_OF, t + LINE_T_OF,LINE_W,LINE_H,0,0)

#define LDEF_WIN(varCon,nxtObj,l,t,w,h,focusID)     \
    DEF_CONTAINER(varCon,NULL,NULL,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, WIN_SH_IDX,WIN_SH_IDX,WIN_SH_IDX,WIN_SH_IDX,   \
    localset_con_keymap,localset_con_callback,  \
    nxtObj, focusID,0)

static char ip_pattern[] = "i00";

LDEF_SEL_MENU_ITEM(g_win_localsetting,localset_item_con1, &localset_item_con2,localset_item_txtname1,localset_item_dhcp,localset_item_line1,1,7,2,   \
                CON_L, CON_T + (CON_H + CON_GAP)*0,CON_W,CON_H, RS_NET_DHCP,\
                STRING_ID,0,2,win_com_onoff_ids)

LDEF_EDIT_MENU_ITEM(g_win_localsetting,localset_item_con2, &localset_item_con3,localset_item_txtname2,localset_item_ip_addr,localset_item_line2,2,1,3,    \
                CON_L, CON_T + (CON_H + CON_GAP)*1,CON_W,CON_H, RS_NET_IP_ADDR,\
                NORMAL_EDIT_MODE,CURSOR_NORMAL,ip_pattern,NULL,NULL,display_strs[0])

LDEF_EDIT_MENU_ITEM(g_win_localsetting,localset_item_con3, &localset_item_con4,localset_item_txtname3,localset_item_subnet_mask,localset_item_line3,3,2,4,  \
                CON_L, CON_T + (CON_H + CON_GAP)*2,CON_W,CON_H, RS_NET_SUBNET_MASK,\
                NORMAL_EDIT_MODE,CURSOR_NORMAL,ip_pattern,NULL,NULL,display_strs[1])


LDEF_EDIT_MENU_ITEM(g_win_localsetting,localset_item_con4, &localset_item_con5,localset_item_txtname4,localset_item_gateway,localset_item_line4,4,3,5,    \
                CON_L, CON_T + (CON_H + CON_GAP)*3,CON_W,CON_H, RS_NET_GATEWAY,\
                NORMAL_EDIT_MODE,CURSOR_NORMAL,ip_pattern,NULL,NULL,display_strs[2])

LDEF_EDIT_MENU_ITEM(g_win_localsetting,localset_item_con5, &localset_item_con6,localset_item_txtname5,localset_item_dns1,localset_item_line5,5,4,6,    \
                CON_L, CON_T + (CON_H + CON_GAP)*4,CON_W,CON_H, RS_NET_DNS_PREFERRED,\
                NORMAL_EDIT_MODE,CURSOR_NORMAL,ip_pattern,NULL,NULL,display_strs[3])

LDEF_EDIT_MENU_ITEM(g_win_localsetting,localset_item_con6, &localset_item_con7,localset_item_txtname6,localset_item_dns2,localset_item_line6,6,5,7,    \
                CON_L, CON_T + (CON_H + CON_GAP)*5,CON_W,CON_H, RS_NET_DNS_ALTERNATE,\
                NORMAL_EDIT_MODE,CURSOR_NORMAL,ip_pattern,NULL,NULL,display_strs[4])

LDEF_TXT_MENU_ITEM(g_win_localsetting,localset_item_con7, NULL,localset_item_txtname7,localset_item_line7,7,6,1,    \
				CON_L, CON_T + (CON_H + CON_GAP)*6,CON_W,CON_H, RS_NET_APPLY)

LDEF_WIN(g_win_localsetting,&localset_item_con1,W_L, W_T, W_W, W_H, 1)


/*******************************************************************************
*   Local functions & variables define
*******************************************************************************/
static UINT16 win_com_onoff_ids[] = 
{
	RS_COMMON_OFF,
	RS_COMMON_ON,
};

static PCONTAINER localset_cons[] = 
{
	&localset_item_con2,
	&localset_item_con3,
	&localset_item_con4,
	&localset_item_con5,
	&localset_item_con6
};

static IP_LOC_CFG net_local_cfg;

static void localset_hdcp_on(BOOL update, UINT32 on)
{
	UINT8 action;
	UINT8 i;
	
	action = on? C_ATTR_INACTIVE : C_ATTR_ACTIVE;

    if( action == C_ATTR_INACTIVE )
    {
        UINT8 bID = g_win_localsetting.FocusObjectID;
        if((bID != IDC_LOCALSET_APPLY) && (bID != IDC_LOCALSET_DHCP))
        {
            g_win_localsetting.FocusObjectID = IDC_LOCALSET_DHCP;
        }
    }

	for(i = 0; i < ARRAY_SIZE(localset_cons); i++)
	{
		set_container_active(localset_cons[i], action);
		if(update)
			OSD_DrawObject( (POBJECT_HEAD)localset_cons[i], C_DRAW_SIGN_EVN_FLG | C_UPDATE_ALL);
	}
}


static void localset_init()
{
	get_local_ip_cfg(&net_local_cfg);
//	libc_printf("start dhcp: %d\n", net_local_cfg.dhcp_on);
	OSD_SetMultiselSel(&localset_item_dhcp, net_local_cfg.dhcp_on);
	localset_hdcp_on(FALSE, net_local_cfg.dhcp_on);
	OSD_SetEditFieldContent(&localset_item_ip_addr, STRING_NUMBER, 
                            ntohl(net_local_cfg.ip_addr));
	OSD_SetEditFieldContent(&localset_item_subnet_mask, STRING_NUMBER,
                            ntohl(net_local_cfg.subnet_mask));
	OSD_SetEditFieldContent(&localset_item_gateway, STRING_NUMBER,
                            ntohl(net_local_cfg.gateway));
	OSD_SetEditFieldContent(&localset_item_dns1, STRING_NUMBER,
                            ntohl(net_local_cfg.dns));
	OSD_SetEditFieldContent(&localset_item_dns2, STRING_NUMBER,
                            ntohl(net_local_cfg.dns2));
}

typedef enum {
	LOCAL_CFG_ERR_NONE = 0,
	LOCAL_CFG_ERR_IP,
	LOCAL_CFG_ERR_SUBNET,
	LOCAL_CFG_ERR_IP_SUBNET,
	LOCAL_CFG_ERR_GATEWAY,
	LOCAL_CFG_ERR_DNS_PREFER,
	LOCAL_CFG_ERR_DNS_ALTER,
	LOCAL_CFG_ERR_MAX /* MUST be the last one */
} LOCAL_CFG_ERR_CODE;

static LOCAL_CFG_ERR_CODE localset_cfg_save(void)
{
	IP_LOC_CFG last_local_cfg;

	/* check address validity */
	if (net_local_cfg.dhcp_on == 0)
	{
		if ((ntohl(net_local_cfg.ip_addr) & 0xFF000000) == 0)
			return LOCAL_CFG_ERR_IP;
		
		if ((ntohl(net_local_cfg.subnet_mask) & 0xFF000000) == 0)
			return LOCAL_CFG_ERR_SUBNET;

		if (ntohl(net_local_cfg.ip_addr & (~net_local_cfg.subnet_mask)) == 0)
			return LOCAL_CFG_ERR_IP_SUBNET;

		if ((ntohl(net_local_cfg.gateway) & 0xFF000000) == 0)
			return LOCAL_CFG_ERR_GATEWAY;
		
		if ((ntohl(net_local_cfg.dns) & 0xFF000000) == 0)
			return LOCAL_CFG_ERR_DNS_PREFER;
		
		if ((ntohl(net_local_cfg.dns2) & 0xFF000000) == 0)
			return LOCAL_CFG_ERR_DNS_ALTER;
	}
	
	get_local_ip_cfg(&last_local_cfg);
    if ((last_local_cfg.dhcp_on == 0) && (net_local_cfg.dhcp_on == 1))
    {            
        libc_printf("set DHCP on!\n");
        libnet_dhcp_on();
    }
    else if ((last_local_cfg.dhcp_on == 1) && (net_local_cfg.dhcp_on == 0))
    {            
        libc_printf("set DHCP off!\n");
        libnet_dhcp_off();            
    }

    if (net_local_cfg.dhcp_on == 0)
    {
        libc_printf("set local IP\n");
        libnet_set_ipconfig(&net_local_cfg);
    }
	set_local_ip_cfg(&net_local_cfg);
    sys_data_save(1);
//	libc_printf("save dhcp: %d\n", net_local_cfg.dhcp_on);
	return LOCAL_CFG_ERR_NONE;
}

/*******************************************************************************
*   key mapping and event callback definition
*******************************************************************************/
static VACTION localset_item_sel_keymap(POBJECT_HEAD pObj, UINT32 key)
{
    VACTION act = VACT_PASS;

    switch(key)
    {
    case V_KEY_LEFT:
        act = VACT_DECREASE;
        break;
    case V_KEY_RIGHT:
        act = VACT_INCREASE;
        break; 
    case V_KEY_ENTER:
        act = VACT_ENTER;
        break; 
    default:
        break;
    }

    return act; 
}

static PRESULT localset_item_sel_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
    PRESULT ret = PROC_PASS;

    switch(event)
    {
    case EVN_PRE_CHANGE:
        break;
    case EVN_POST_CHANGE:
		net_local_cfg.dhcp_on = param1;
		localset_hdcp_on(TRUE, param1);
        break; 
    case EVN_REQUEST_STRING:
        break;
        
    case EVN_UNKNOWN_ACTION:
        
        break;
    }
    return ret;
}

static VACTION localset_item_con_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act = VACT_PASS;
	switch (key)
	{
		case V_KEY_ENTER:     
			act = VACT_ENTER;
			break;     
		default:
			act = VACT_PASS;
			break;
	}
	return act;
}

static PRESULT localset_item_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
    PRESULT ret = PROC_PASS;
    VACTION unact;
	UINT8 bID = OSD_GetObjID(pObj);
	
	switch( event)
	{
		case EVN_UNKNOWN_ACTION:
			unact = (VACTION)(param1 >> 16);
	        if ((bID == IDC_LOCALSET_APPLY) && (unact == VACT_ENTER))
	        {
				char hint[64];
				UINT8 bNewFocusID = IDC_LOCALSET_APPLY, back_saved;
				LOCAL_CFG_ERR_CODE err_code = localset_cfg_save();
				switch (err_code)
				{
					case LOCAL_CFG_ERR_NONE:
						STRCPY(hint, "Apply network local setting...");
						bNewFocusID = IDC_LOCALSET_APPLY;
						break;
					case LOCAL_CFG_ERR_IP:
						STRCPY(hint, "Invalid IP address");
						bNewFocusID = IDC_LOCALSET_IP_ADDR;
						break;
					case LOCAL_CFG_ERR_SUBNET:
						STRCPY(hint, "Invalid subnet mask");
						bNewFocusID = IDC_LOCALSET_SUBNET_MASK;
						break;
					case LOCAL_CFG_ERR_IP_SUBNET:
						STRCPY(hint, "Invalid IP address or subnet mask");
						bNewFocusID = IDC_LOCALSET_IP_ADDR;
						break;
					case LOCAL_CFG_ERR_GATEWAY:
						STRCPY(hint, "Invalid gateway");
						bNewFocusID = IDC_LOCALSET_GATEWAY;
						break;
					case LOCAL_CFG_ERR_DNS_PREFER:
						STRCPY(hint, "Invalid preferred DNS");
						bNewFocusID = IDC_LOCALSET_DNS1;
						break;
					case LOCAL_CFG_ERR_DNS_ALTER:
						STRCPY(hint, "Invalid alternate DNS");
						bNewFocusID = IDC_LOCALSET_DNS2;
						break;
					default:
						err_code = LOCAL_CFG_ERR_MAX; /* don't show anything */
						break;
				}
				
				if (err_code < LOCAL_CFG_ERR_MAX)
				{
					win_compopup_init(WIN_POPUP_TYPE_SMSG);
					win_compopup_set_msg(hint, NULL, 0);
					win_compopup_open_ext(&back_saved); 
					osal_task_sleep(1000);
					win_compopup_smsg_restoreback();
					OSD_ContainerChgFocus(&g_win_localsetting, bNewFocusID,
										  C_DRAW_SIGN_EVN_FLG | C_UPDATE_FOCUS);
				}
	        }
			break;
		default:
			break;
	}
    return ret;
}

static VACTION  localset_item_edf_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act;
	
	switch(key)
    {
	case V_KEY_0:	case V_KEY_1:	case V_KEY_2:	case V_KEY_3:
	case V_KEY_4:	case V_KEY_5:	case V_KEY_6:	case V_KEY_7:
	case V_KEY_8:	case V_KEY_9:
		act = key - V_KEY_0 + VACT_NUM_0;
		break;
	case V_KEY_LEFT:
		act = VACT_EDIT_LEFT;
		break;
	case V_KEY_RIGHT:
		act = VACT_EDIT_RIGHT;
		break;		
	default:					
		act = VACT_PASS;
	}

	return act;	 
}

static PRESULT  localset_item_edf_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT8 bID;
	UINT8 status;
	EDIT_FIELD* edf;
	UINT8 back_save;
	UINT32 value;
    char tmpStr[32];

	bID = OSD_GetObjID(pObj);

	edf = (EDIT_FIELD*)pObj;

	switch(event)
	{
	case EVN_PRE_CHANGE:
		
		break;
	case EVN_POST_CHANGE:
		value = OSD_GetEditFieldContent((PEDIT_FIELD)pObj);
		switch(bID)
		{
			case IDC_LOCALSET_IP_ADDR:
				net_local_cfg.ip_addr = htonl(value);
				break;
			case IDC_LOCALSET_SUBNET_MASK:
				net_local_cfg.subnet_mask = htonl(value);
				break;
			case IDC_LOCALSET_GATEWAY:
				net_local_cfg.gateway = htonl(value);
				break;
			case IDC_LOCALSET_DNS1:
				net_local_cfg.dns = htonl(value);
				break;                
            case IDC_LOCALSET_DNS2:
                net_local_cfg.dns2 = htonl(value);
                break;
		}
		//libc_printf("POST: ip %xh, get value = %xh\n",param1,value);
		break;
	case EVN_PARENT_FOCUS_POST_LOSE:
		break;		
	case EVN_DATA_INVALID:		
		win_compopup_init(WIN_POPUP_TYPE_OK);
		win_compopup_set_msg("Invalid address number!", NULL, 0);
		win_compopup_open_ext(&back_save);
		ret = PROC_LOOP;
		break;
		
	}

	return ret;
}

static VACTION localset_con_keymap(POBJECT_HEAD pObj, UINT32 key)
{
    VACTION act;
    
    switch(key)
    {
    case V_KEY_UP:
        act = VACT_CURSOR_UP;
        break;
    case V_KEY_DOWN:
        act = VACT_CURSOR_DOWN;
        break;      
    case V_KEY_EXIT:
    case V_KEY_MENU:
        act = VACT_CLOSE;
        break;
    default:    
        act = VACT_PASS;
        break;
    }

    return act;
}

static PRESULT localset_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
    PRESULT ret = PROC_PASS;
    VACTION unact;
    IP_LOC_CFG last_local_cfg;

    switch(event)
    {
    case EVN_PRE_OPEN:
        wincom_open_title((POBJECT_HEAD)&g_win_localsetting,RS_NET_LOCAL_SETTING, 0);
		localset_init();
        break;
    case EVN_PRE_CLOSE:
		//localset_cfg_save();
        /* Make OSD not flickering */
        *((UINT32*)param2) &= ~C_CLOSE_CLRBACK_FLG; 
        break;
    default:
        break;
    }

    return ret; 
}


/*******************************************************************************
*   other functions  definition
*******************************************************************************/

#endif /* NETWORK_SUPPORT */
